using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_Shop_AddInvoice : Member, IRequiresSessionState
{
	protected Label LabCusName;
	protected Label LabOrderNum;
	protected Label LabMoney;
	protected Label LabMoneyRecevice;
	protected Label LabInvoiceContent;
	protected HtmlInputText InvoiceDate;
	protected HtmlSelect Select1;
	protected HtmlInputText InvoiceNum;
	protected RequiredFieldValidator Ref2;
	protected HtmlInputText InvoiceTitle;
	protected RequiredFieldValidator Ref1;
	protected TextBox InvoiceContent;
	protected HtmlInputText TotalMoney;
	protected RangeValidator RangeValidator1;
	protected HtmlInputText Drawer;
	protected RequiredFieldValidator RequiredFieldValidator3;
	protected CheckBox CheckSendMobileMesToCus;
	protected CheckBox CheckSendMesMesToCus;
	protected CheckBox CheckSendEmailMesToCus;
	protected Button Button1;
	protected Button Button2;
	public static string UserName = "";
	public static string SalerName = "";
	public static string UserTureName = "";
	public static string SalerTureName = "";
	public static int OrderFormID = 0;
	public static string OrderFormNum = "";
	public static int UserID = 0;
	public static int SalerID = 0;
	public static decimal MoneyTotal = 0m;
	public static decimal MoneyReceipt;
	public static string Email = "";
	public static string UserEmail = "";
	public static string SalerEmail = "";
	public static string OrderInvoiceContent = "";
	public static string Inputer = "";
	protected DataTable DTOrder;
	protected string Msg;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		Member_Shop_AddInvoice.OrderFormNum = Fetch.Get("OrderFormNum");
		if (Member_Shop_AddInvoice.OrderFormNum == string.Empty)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Common/NotData", new string[0]), "");
		}
		if (!base.IsPostBack)
		{
			this.InvoiceDate.Value = DateTime.Now.ToShortDateString();
			Shop_Order shop_Order = new Shop_Order(this.conn);
			this.DTOrder = shop_Order.GetOrderByOrderFormNum(Member_Shop_AddInvoice.OrderFormNum);
			if (this.DTOrder.Rows.Count <= 0)
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Common/NotData", new string[0]), "");
			}
			Member_Shop_AddInvoice.OrderFormID = int.Parse(this.DTOrder.Rows[0]["OrderFormID"].IsNull(new object[0]));
			Member_Shop_AddInvoice.UserID = int.Parse(this.DTOrder.Rows[0]["UserID"].IsNull(new object[0]));
			Member_Shop_AddInvoice.SalerID = int.Parse(this.DTOrder.Rows[0]["SalerID"].IsNull(new object[0]));
			this.LabOrderNum.Text = this.DTOrder.Rows[0]["OrderFormNum"].IsNull(new object[0]);
			this.InvoiceContent.Text = (this.LabInvoiceContent.Text = this.DTOrder.Rows[0]["InvoiceContent"].IsNull(new object[0]));
			this.LabMoneyRecevice.Text = this.DTOrder.Rows[0]["MoneyReceipt"].IsNull(new object[0]);
			this.LabMoney.Text = this.DTOrder.Rows[0]["MoneyTotal"].IsNull(new object[0]);
			Member_Shop_AddInvoice.Email = this.DTOrder.Rows[0]["Email"].IsNull(new object[0]);
			if (Member_Shop_AddInvoice.SalerID != base.user.UserID)
			{
				this.WriteErrMsg("", Language.Get("Common/NotData"), "");
			}
			UserBll userBll = new UserBll(this.conn);
			UserInfoBll userInfoBll = new UserInfoBll(this.conn);
			DataTable userByUserID = userBll.GetUserByUserID(Member_Shop_AddInvoice.UserID);
			DataTable userByUserID2 = userBll.GetUserByUserID(Member_Shop_AddInvoice.SalerID);
			DataTable userInfoByUserID = userInfoBll.GetUserInfoByUserID(Member_Shop_AddInvoice.UserID);
			DataTable userInfoByUserID2 = userInfoBll.GetUserInfoByUserID(Member_Shop_AddInvoice.SalerID);
			this.LabCusName.Text = userInfoByUserID.Rows[0]["TrueName"].IsNull(new object[0]);
			Member_Shop_AddInvoice.UserEmail = userByUserID.Rows[0]["Email"].IsNull(new object[0]);
			Member_Shop_AddInvoice.Inputer = (this.Drawer.Value = userInfoByUserID2.Rows[0]["TrueName"].IsNull(new object[0]));
			if (userInfoByUserID2.Rows[0]["TrueName"] != null && !string.IsNullOrEmpty(userInfoByUserID2.Rows[0]["TrueName"].IsNull(new object[0])))
			{
				Member_Shop_AddInvoice.UserTureName = userInfoByUserID.Rows[0]["TrueName"].IsNull(new object[0]);
			}
			else
			{
				Member_Shop_AddInvoice.UserTureName = "未知";
			}
			Member_Shop_AddInvoice.SalerTureName = userInfoByUserID2.Rows[0]["TrueName"].IsNull(new object[0]);
			Member_Shop_AddInvoice.UserName = userByUserID.Rows[0]["UserName"].IsNull(new object[0]);
			Member_Shop_AddInvoice.SalerName = userByUserID2.Rows[0]["UserName"].IsNull(new object[0]);
			Member_Shop_AddInvoice.SalerEmail = userByUserID2.Rows[0]["Email"].IsNull(new object[0]);
			userByUserID.Dispose();
			userByUserID2.Dispose();
			userInfoByUserID.Dispose();
			userInfoByUserID2.Dispose();
			this.InvoiceDate.Attributes.Add("onfocus", string.Concat(new string[]
			{
				"show_cele_date(",
				this.InvoiceDate.UniqueID,
				",'','',",
				this.InvoiceDate.UniqueID,
				");"
			}));
		}
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		string text = this.config["MailSmtpServer"].IsNull(new object[0]);
		string text2 = this.config["MailServerUserName"].IsNull(new object[0]);
		string text3 = this.config["MailServerPassWord"].IsNull(new object[0]);
		string text4 = this.config["MailServerFrom"].IsNull(new object[0]);
		Shop_InvoiceItem shop_InvoiceItem = new Shop_InvoiceItem(this.conn);
		shop_InvoiceItem.AddSalerInvoice(Member_Shop_AddInvoice.OrderFormID, Member_Shop_AddInvoice.UserID, Member_Shop_AddInvoice.SalerID, decimal.Parse(this.TotalMoney.Value), int.Parse(this.Select1.Value), this.InvoiceNum.Value, this.InvoiceTitle.Value, this.InvoiceContent.Text, this.Drawer.Value, Member_Shop_AddInvoice.Inputer, DateTime.Parse(DateTime.Now.ToLocalTime().IsNull(new object[0])));
		this.Msg += Language.Get("Common/Success");
		this.SendMsg();
		this.WriteSuccessMsg("", this.Msg, "Shop_BuyOrder.aspx?OrderFormNum=" + Member_Shop_AddInvoice.OrderFormNum);
	}
	protected void SendMsg()
	{
		string text = Member_Shop_AddInvoice.UserTureName;
		if (text == string.Empty)
		{
			text = Member_Shop_AddInvoice.UserName;
		}
		string text2 = "开发票通知";
		string text3 = this.config["MessageOfInvoiced"].IsNull(new object[0]);
		text3 = text3.Replace("{$UserName$}", text);
		text3 = text3.Replace("{$InputTime$}", DateTime.Now.IsNull(new object[0]));
		text3 = text3.Replace("{$OrderFormNum$}", Member_Shop_AddInvoice.OrderFormNum);
		if (this.CheckSendMesMesToCus.Checked)
		{
			MessageBll messageBll = new MessageBll(this.conn);
			if (messageBll.AddMessage(Member_Shop_AddInvoice.SalerName, "Users", text2, text3, 0, 0, 1, 0, Member_Shop_AddInvoice.UserName, "", 1))
			{
				this.Msg = this.Msg + "<br/>" + Language.GetMemberMsg("Order/Notice/MessageSuccess", new string[0]);
			}
		}
		if (this.CheckSendEmailMesToCus.Checked)
		{
			string text4 = this.config["SiteName"].IsNull(new object[0]);
			string smtpserver = this.config["MailSmtpServer"].IsNull(new object[0]);
			string mailuser = this.config["MailServerUserName"].IsNull(new object[0]);
			string mailpassword = this.config["MailServerPassWord"].IsNull(new object[0]);
			string mailFrom = this.config["MailServerFrom"].IsNull(new object[0]);
			Email email = new Email();
			if (email.SendEmail(smtpserver, mailuser, mailpassword, mailFrom, text3, Member_Shop_AddInvoice.UserEmail, text2))
			{
				this.Msg = this.Msg + "<br/>" + Language.GetMemberMsg("Order/Notice/EmailSuccess", new string[0]);
			}
		}
		if (this.CheckSendMobileMesToCus.Checked)
		{
			if (this.DTOrder != null && this.DTOrder.Rows.Count > 0)
			{
				if (this.DTOrder.Rows[0]["Mobile"] != null && this.DTOrder.Rows[0]["Mobile"].IsNull(new object[0]) != "")
				{
					string receiveNumber = this.DTOrder.Rows[0]["Mobile"].IsNull(new object[0]);
					MobileMessage mobileMessage = new MobileMessage();
					if (mobileMessage.Send(receiveNumber, text3, Member_Shop_AddInvoice.UserName))
					{
						this.Msg = this.Msg + "<br/>" + Language.GetMemberMsg("Order/Notice/MobileSuccess", new string[0]);
					}
				}
			}
		}
	}
}
